from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

# 设置正确的驱动路径
service = ChromeService(executable_path="D:\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)


# 打开网页
driver.get("https://example.com")

# 定位元素
element = driver.find_element(By.ID, "element_id")

# 创建 ActionChains 对象
actions = ActionChains(driver)

# 点击操作
actions.click(element).perform()

# 双击操作
actions.double_click(element).perform()

# 右键点击操作
actions.context_click(element).perform()

# 关闭浏览器
driver.quit()



from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

# 设置正确的驱动路径
service = ChromeService(executable_path="D:\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)

# 打开网页
driver.get("https://www.example.com")

# 鼠标操作
element = driver.find_element(By.ID, "button")
actions = ActionChains(driver)
actions.move_to_element(element).click().perform()

# 键盘操作
input_box = driver.find_element(By.ID, "input-box")
input_box.send_keys("Hello, Selenium!")
input_box.send_keys(Keys.ENTER)

# 关闭浏览器
driver.quit()